// 功能说明
// 1.replywindow 每个评论的回复工能
// 2.assessBtn点击评论的展开功能
// 3.commentlimit 评论展开后需要再次调用，限制评论字数
// 4.func()点赞收藏等功能的样式以及向后端发送请求（有bug）
// 5.YesOrNo判断是否关注，点赞等
// 6.more（）每个评论下若有多条评论，则以弹窗显示
// 7.getinfo获取登录用户的所有信息,封装到对象中

function getInfo() {
  var user = new Object();
  user = {};
  $.ajax({
    url: "/weibo/user/getLoginUserInfo",
    type: "get",
    async: false,
    data: {},
    success: function (result) {
      user.address = result.address;
      user.age = result.age;
      user.avatarUrl = result.avatarUrl;
      user.ban = result.ban;
      user.id = result.id;
      user.isManager = result.isManager;
      user.label = result.label;
      user.official = result.official;
      user.sex = result.sex;
      user.username = result.username;
      user.vip = result.vip;
    },
    error: function () {},
  });
  return user;
}

let user = getInfo();

let news = document.getElementsByClassName("news");
let baseurl = "/weibo/blog";
replyWindow();
// 评论的回复弹窗
function replyWindow() {
  var textarea = document.querySelector(".reply-text");
  var replyBtn = document.querySelector(".reply-btn.disable");
  var reply = document.getElementsByClassName("reply");
  // 监听高度
  if (textarea) {
    textarea.addEventListener("input", function (e) {
      if (textarea.value == "") {
        replyBtn.setAttribute("disabled", true);
        replyBtn.classList.add("disable");
      } else {
        replyBtn.removeAttribute("disabled");
        replyBtn.classList.remove("disable");
      }
      this.style.height = "inherit";
      this.style.height = `${this.scrollHeight}px`;
    });
  }

  var cancel = document.querySelector(".top-cancel");
  var mask = document.querySelector(".mask");
  if (cancel) {
    cancel.onclick = function () {
      mask.style.display = "none";
      document.body.style.overflow = "";
    };
  }
  if (reply.length > 0) {
    for (let i = 0; i < reply.length; i++) {
      reply[i].onclick = function () {
        document.body.style.overflow = "hidden";
        let cid = reply[i].getAttribute("cid");
        mask.style.display = "flex";

        replyBtn.onclick = function () {
          let user = getInfo();
          if (user.ban == 1) {
            return showCustomAlert("您已被禁言，禁止回复！");
          }
          let comment = document.querySelector(".reply-text").value;
          // 进行二级评论(获取博文id)

          // 获取用户信息

          if (document.getElementsByClassName("assess").length > 0) {
            $.ajax({
              url: "/weibo/blog/publishSecondComment",
              type: "post",
              data: {
                id: cid,
                comment,
              },
              success: function (result) {
                $.ajax({
                  url: "/weibo/user/getLoginUserInfo",
                  type: "get",
                  data: {},
                  success: function (result) {
                    let name = result.username;
                    let avatarUrl = result.avatarUrl;

                    let time = new Date();
                    document.querySelector(".reply-text").value = "";
                    mask.style.display = "none";

                    document.body.style.overflow = "";
                    showCustomAlert("回复成功", true);
                    // 获取cid
                    // 渲染评论
                    let newlist2 = $("#content").find(`.item1[cid=${cid}]`);
                    $("#content").find(`.item1[cid=${cid}]`)
                      .after(`<div class="list2">
            <div class="list2-bar"></div>
            <div class="list2-details">
              <a href="" class="list2-name"><span>${name}</span></a>
              <span class="list2-content">${comment}</span>
            </div>
            <div class="list2-bottom">
              <div class="list2-time">${formaData(time)}</div>
            </div>
          </div>`);
                  },
                  error: function () {},
                });
              },
            });
          } else {
            // 针对收到评论的页面
            $.ajax({
              url: "/weibo/blog/publishSecondComment",
              type: "post",
              data: {
                id: cid,
                comment,
              },
              success: function () {
                mask.style.display = "none";
                document.body.style.overflow = "";
                showCustomAlert("回复成功", true);
                // 清空输入框
                document.querySelector(".reply-text").value = "";
              },
            });
          }
        };
      };
    }
  }

  // 监听字数
  if (textarea) {
    textarea.onkeyup = function () {
      let ddl = document.querySelector(".ddl");
      let str = textarea.value;

      ddl.innerHTML = `还可输入${100 - textarea.value.length}字`;
      if (textarea.value.length >= 100) {
        ddl.innerHTML = "还可输入0字";
        textarea.value = textarea.value.substr(0, 100);
      }
    };
  }
}
//  搜索的下拉菜单以及进行模糊查询

let searchList = document.querySelector(".search-list");
let topSearch = document.querySelector(".top-search");
let topinput = document.querySelector("#top-input");
let icon = document.querySelector(".top-search").querySelector(".iconfont");
let all = document.getElementsByTagName("body")[0];

topinput.addEventListener("blur", function () {
  all.onclick = function (e) {
    if (!topSearch.contains(e.target)) {
      searchList.style.display = "none";
      icon.style.color = "black";
    }
  };
});
topinput.addEventListener("focus", function () {
  topinput.addEventListener("input", function () {
    let text = topinput.value;

    if (text != "") {
      searchList.style.display = "block";
      icon.style.color = "#ff8200";
    } else {
      searchList.style.display = "none";
      icon.style.color = "black";
    }
  });
});

// 设置的下拉菜单
var set = document.querySelectorAll(".setting")[0];
set.addEventListener("mouseenter", function (e) {
  let list = document.querySelector(".setting-list");
  list.style.display = "block";
});
set.addEventListener("mouseleave", function (e) {
  let list = document.querySelector(".setting-list");
  list.style.display = "none";
});

// 评论部分的展开
function assessBtn() {
  let assess = document.getElementsByClassName("assess");
  let news = document.getElementsByClassName("news");
  console.log("新闻数量" + news.length);
  let commentBtn = document.getElementsByClassName("comment-btn");
  for (let i = 0; i < assess.length; i++) {
    assess.num = i;
    news.num = i;
    commentBtn.num = i;
  }
  let click = 0;
  if (assess.length > 0) {
    for (let i = 0; i < news.length; i++) {
      assess[i].onclick = function () {
        let bid = news[i].getAttribute("bid");
        let spread = news[i].querySelector(".spread");
        if (!spread.classList.contains(click)) {
          spread.style.display = "block";
          spread.classList.add("click")
        } else {
          // click = 0;
          spread.classList.remove("click")
          spread.style.display = "none";
        }

        // 评论展开时发送请求
        $.ajax({
          url: `/weibo/blog/getBlogComment?id=${bid}`,
          type: "get",
          success: function (result) {
            console.log(result.length);
            let comment = news[i].querySelector(".comment");
            comment.innerHTML = "";
            let blogSkip = news[i].querySelector(".blog-skip");
            console.log(blogSkip);

            if (result.length > 5) {
              console.log(111);
              blogSkip.classList.remove("hidden");
              for (let i = 0; i < 5; i++) {
                if (result[i].likes == 0) {
                  result[i].likes = "";
                }
                comment.innerHTML =
                  comment.innerHTML +
                  ` <div class="item1" cid="${result[i].id}">
                    <div class="comment-list">
                      <a href="">
                       <div class="comment-head">
                          <img
                           
                            src="${result[i].userAvatarUrl}"
                            alt=""
                           />
                        </div>
                      </a>
                      <div class="comment-details">
                        <a href="" class="comment-name"> <span>${setText(
                          result[i].username
                        )}</span> </a>:
                        <span class="c-content">${setText(
                          result[i].comment
                        )}</span>
                      <div class="comment-bottom">
                         <div class="c-time">${
                           result[i].publishTime
                         }   ${setText(result[i].address)}</div>
                         <div class="comment-fn">
                            <div class="c-complain" otherId=${
                              result[i].otherId
                            } cid="${
                    result[i].id
                  }" onclick="removeFirstComment(this)">
                            <i class="iconfont remove hidden">&#xe64c;</i>
                           
                            </div>
                            <div class="reply" cid=${result[i].id} logid=${
                    result[i].uid
                  }>
                              <i class="iconfont">&#xe695;</i>
                            </div>
                            <div class="c-like" onclick="likeComment(this)"  cid=${
                              result[i].id
                            }>
                              <i class="iconfont">&#xe600;</i><span>${
                                result[i].likes
                              }</span>
                            </div>
                          </div> 
                        </div>
                      </div>
                    </div>
                 `;
              }
              let item1 = news[i].getElementsByClassName("item1");
              for (let i = 0; i < 5; i++) {
                // 二级评论的数据（数组）

                let list = result[i].list;

                if (result[i].likes == 0) {
                  result[i].likes = " ";
                }

                if (list.length > 0) {
                  for (let j = 0; j < 1; j++) {
                    if (list[j].likes == 0) {
                      list[j].likes = "";
                    }
                    item1[i].innerHTML =
                      item1[i].innerHTML +
                      `<div class="list2" cid=${list[j].id}>
                  <div class="list2-bar"></div>
                  <div class="list2-details">
                    <a href="" class="list2-name"><span>${setText(
                      list[j].username
                    )}:</span></a>
                    <span class="list2-content">${setText(
                      list[j].comment
                    )}</span>
                  </div>
                  <div class="list2-bottom">
                    <div class="list2-time">${list[j].publishTime}  ${
                        list[j].address
                      }</div>
                      <div class="list2-fn">
                      <div class="list2-complain" otherId=${list[j].otherId}>
                      <i class="iconfont remove hidden" onclick="removeSecondComment(this)">&#xe64c;</i>
                      </div>
                      
                      <div class="list2-like" onclick="likeComment(this)" cid=${
                        list[j].id
                      }>
                        <i class="iconfont">&#xe600;</i> <span>${
                          list[j].likes
                        }</span>
                      </div>
                    </div>
            </div>
                  </div>
                </div>`;
                  }

                  // 下面循环结尾多一个</div>是对item1进行结尾
                  if (list.length > 1) {
                    item1[i].innerHTML =
                      item1[i].innerHTML +
                      `<div class="list2-more ">
                  <div class="list2-bar"></div>
                       <a href="javascript:;" class="more-reply" id=${bid} index=${i}>共${list.length}条回复</a>
                       <i class="iconfont bottom">&#xe62e;</i>
                     </div>
                   </div>`;
                  } else {
                    comment.innerHTML = comment.innerHTML + `</div>`;
                  }
                }
                judgeSecCom(comment);
                more();
                replyWindow();
                commentfn();
                judgecom(comment);
                commentlimit();
                islike(comment);
                issecLike();
              }
            } else {
              if (!blogSkip.classList.contains("hidden")) {
                blogSkip.classList.add("hidden");
              }
              for (let i = 0; i < result.length; i++) {
                if (result[i].likes == 0) {
                  result[i].likes = "";
                }

                comment.innerHTML =
                  comment.innerHTML +
                  ` <div class="item1" cid="${result[i].id}">
                    <div class="comment-list">
                      <a href="">
                       <div class="comment-head">
                          <img
                           
                            src="${result[i].userAvatarUrl}"
                            alt=""
                           />
                        </div>
                      </a>
                      <div class="comment-details">
                        <a href="" class="comment-name"> <span>${setText(
                          result[i].username
                        )}</span> </a>:
                        <span class="c-content">${setText(
                          result[i].comment
                        )}</span>
                      <div class="comment-bottom">
                         <div class="c-time">${
                           result[i].publishTime
                         }   ${setText(result[i].address)}</div>
                         <div class="comment-fn">
                            <div class="c-complain" otherId=${
                              result[i].otherId
                            } cid="${
                    result[i].id
                  }" onclick="removeFirstComment(this)">
                            <i class="iconfont remove hidden">&#xe64c;</i>
                           
                            </div>
                            <div class="reply" cid=${result[i].id} logid=${
                    result[i].uid
                  }>
                              <i class="iconfont">&#xe695;</i>
                            </div>
                            <div class="c-like" onclick="likeComment(this)"  cid=${
                              result[i].id
                            }>
                              <i class="iconfont">&#xe600;</i><span>${
                                result[i].likes
                              }</span>
                            </div>
                          </div> 
                        </div>
                      </div>
                    </div>
                 `;
              }
              let item1 = news[i].getElementsByClassName("item1");
              for (let i = 0; i < result.length; i++) {
                // 二级评论的数据（数组）

                let list = result[i].list;

                if (result[i].likes == 0) {
                  result[i].likes = " ";
                }

                if (list.length > 0) {
                  for (let j = 0; j < 1; j++) {
                    if (list[j].likes == 0) {
                      list[j].likes = "";
                    }
                    item1[i].innerHTML =
                      item1[i].innerHTML +
                      `<div class="list2" cid=${list[j].id}>
                  <div class="list2-bar"></div>
                  <div class="list2-details">
                    <a href="" class="list2-name"><span>${setText(
                      list[j].username
                    )}:</span></a>
                    <span class="list2-content">${setText(
                      list[j].comment
                    )}</span>
                  </div>
                  <div class="list2-bottom">
                    <div class="list2-time">${list[j].publishTime}  ${
                        list[j].address
                      }</div>
                      <div class="list2-fn">
                      <div class="list2-complain" otherId=${list[j].otherId}>
                      <i class="iconfont remove hidden" onclick="removeSecondComment(this)">&#xe64c;</i>
                      </div>
                      
                      <div class="list2-like" onclick="likeComment(this)" cid=${
                        list[j].id
                      }>
                        <i class="iconfont">&#xe600;</i> <span>${
                          list[j].likes
                        }</span>
                      </div>
                    </div>
            </div>
                  </div>
                </div>`;
                  }

                  // 下面循环结尾多一个</div>是对item1进行结尾
                  if (list.length > 1) {
                    item1[i].innerHTML =
                      item1[i].innerHTML +
                      `<div class="list2-more ">
                  <div class="list2-bar"></div>
                       <a href="javascript:;" class="more-reply" id=${bid} index=${i}>共${list.length}条回复</a>
                       <i class="iconfont bottom">&#xe62e;</i>
                     </div>
                   </div>`;
                  } else {
                    comment.innerHTML = comment.innerHTML + `</div>`;
                  }
                }
                judgeSecCom(comment);
                more();
                replyWindow();
                commentfn();
                judgecom(comment);
                commentlimit();
                islike(comment);
                issecLike();
              }
            }
          },
          error: function () {},
        });
      };
    }
  }
}

assessBtn();
// 评论框字数限制
function commentlimit() {
  let commentBtn = document.getElementsByClassName("comment-btn");
  let commentddl = document.getElementsByClassName("comment-ddl");
  let commentText = document.getElementsByClassName("comment-text");
  if (commentText.length > 0) {
    for (let i = 0; i < commentText.length; i++) {
      commentText[i].addEventListener("input", function () {
        if (commentText[i].value == "") {
          commentBtn[i].setAttribute("disabled", true);
          commentBtn[i].classList.add("disable");
        } else {
          commentBtn[i].removeAttribute("disabled", true);
          commentBtn[i].classList.remove("disable");
        }

        this.style.height = `${this.scrollHeight}px`;
        // commentBtn[i].onclick;
      });
      commentddl[i].innerHTML = `还可输入${
        140 - commentText[i].value.length
      }字`;
      if (commentText[i].value.length >= 140) {
        commentddl[i].innerHTML = "还可输入0字";
        commentText[i].value = commentText[i].value.substr(0, 140);
      }
      commentText[i].onkeyup = function () {
        commentddl[i].innerHTML = `还可输入${
          140 - commentText[i].value.length
        }字`;
        if (commentText[i].value.length >= 140) {
          commentddl[i].innerHTML = "还可输入0字";
          commentText[i].value = commentText[i].value.substr(0, 140);
        }
      };
    }
  }
}
commentlimit();
YesOrNo();
// 点赞收藏等效果
function func() {
  let news = document.getElementsByClassName("news");
  let store = document.getElementsByClassName("store");
  let like = document.getElementsByClassName("like");
  let share = document.getElementsByClassName("share");
  let attention = document.getElementsByClassName("top-attention-btn");

  if (news.length > 0) {
    for (let i = 0; i < news.length; i++) {
      let bid = news[i].getAttribute("bid");
      let uid = document.getElementsByClassName("news")[i].getAttribute("uid");
      if (store.length > 0) {
        store[i].f = 0;
        store[i].onclick = function () {
          let icon = store[i].querySelector(".iconfont");
          let span = store[i].querySelector("span");
          if (store[i].f == 0) {
            $.ajax({
              url: `${baseurl}/collectOtherBlog`,
              type: "get",
              data: {
                id: bid,
              },
              success: function (result) {
                icon.innerHTML = "&#xe663";
                icon.style.color = "#feaf2f";
                store[i].f = 1;
                span.style.color = "#feaf2f";
              },
            });
          } else {
            $.ajax({
              url: `${baseurl}/notCollectOtherBlog`,
              type: "get",
              data: {
                id: bid,
              },
              success: function (result) {
                icon.innerHTML = "&#xe647";
                icon.style.color = "inherit";
                span.style.color = "inherit";
                store[i].f = 0;
              },
            });
          }
        };
      }
      if (like.length > 0) {
        // 点赞

        like[i].f = 0;
        like[i].onclick = function () {
          // 属性为0则表示没有
          // 属性为1则表示有

          let icon = like[i].querySelector(".iconfont");
          let span = like[i].querySelector("span");
          let likeText = 0 + like[i].getElementsByTagName("span")[0].innerHTML;
          if (like[i].f == 0) {
            // 发送点赞请求
            $.ajax({
              url: "/weibo/blog/likeBlog",
              type: "post",
              data: {
                bid: bid,
              },
              success: function (result) {
                icon.innerHTML = "&#xe65f;";
                icon.style.color = "#feaf2f";
                like[i].f = 1;
                span.style.color = "#feaf2f";

                if (Number(likeText) == NaN) {
                  likeText = null;
                  likeText = Number(likeText);
                  likeText++;
                } else {
                  likeText = parseInt(likeText);
                  likeText++;
                }

                like[i].getElementsByTagName("span")[0].innerHTML = likeText;
              },
              error: function (result) {},
            });
          } else {
            $.ajax({
              url: "/weibo/blog/notLikeBlog",
              type: "post",
              data: {
                bid: bid,
              },
              success: function (result) {
                icon.innerHTML = "&#xe62b;";
                icon.style.color = "inherit";
                span.style.color = "inherit";
                like[i].f = 0;

                likeText = Number(likeText);
                if (likeText > 1) {
                  likeText--;
                } else {
                  likeText = "点赞";
                }

                like[i].getElementsByTagName("span")[0].innerHTML = likeText;
              },
              error: function (result) {},
            });
          }
        };
      }

      if (share.length > 0) {
        // 转发
        // share[i].f = 0;
        share[i].onclick = function () {
          let icon = share[i].querySelector(".iconfont");
          let span = share[i].querySelector("span");
          let shareText = share[i].getElementsByTagName("span")[0].innerHTML;

          if (share[i].can == 1) {
            return showCustomAlert("您已转发过，请三分钟后再进行操作");
          } else {
            $.ajax({
              url: `${baseurl}/forwardTheBlog`,
              type: "post",
              data: {
                bid: bid,
                message: "转发文章",
              },
              success: function (result) {
                showCustomAlert("转发成功", true);
                share[i].can = 1;
                if (Number(shareText) == NaN) {
                  shareText = null;
                  shareText = Number(shareText);
                  shareText++;
                } else {
                  parseInt(shareText);
                  shareText++;
                }
                share[i].getElementsByTagName("span")[0].innerHTML = shareText;
                setTimeout(function () {
                  share[i].can = 0;
                }, 180000);
              },
            });
          }
        };
      }

      // 关注（先判断是否有关注按钮）
      // 传用户id

      if (document.getElementsByClassName("top-attention-btn").length != 0) {
        attention[i].f = 0;
        attention[i].onclick = function () {
          if (attention[i].f == 0) {
            $.ajax({
              url: "/weibo/user/concernOtherUser",
              type: "post",
              data: {
                id: uid,
              },
              success: function (result) {
                attention[i].innerHTML = `
                <i class="iconfont">&#xe664;</i>已经关注
             `;
                attention[i].f = 1;
                // attention[i].setAttribute("disabled", true);
                attention[i].classList.add("already");
                // attention[i].style.pointEvents = "none";
                // 重新渲染
                YesOrNo();
              },
              error: function () {},
            });
          } else {
            $.ajax({
              url: `/weibo/user/notConcernOtherUser`,
              type: "post",
              data: {
                id: uid,
              },
              success: function (result) {
                customConfirm("确定取消关注该用户？", function (result) {
                  if (result) {
                    attention[
                      i
                    ].innerHTML = ` <i class="iconfont">&#xe7df;</i>关注`;
                    attention[i].classList.remove("already");
                    attention[i].f = 0;
                    YesOrNo();
                  }
                });
              },
            });
          }
        };
      }
    }
  }
}

func();
// 判断用户是否点赞收藏关注等等
// 思路获取所有文章，挨个判断
function YesOrNo() {
  // 是否点赞(传id)
  let store = document.getElementsByClassName("store");
  let like = document.getElementsByClassName("like");
  let share = document.getElementsByClassName("share");
  let attention = document.getElementsByClassName("top-attention-btn");
  let news = document.getElementsByClassName("news");
  if (news.length > 0) {
    for (let i = 0; i < news.length; i++) {
      let id = news[i].getAttribute("bid");
      let uid = news[i].getAttribute("uid");

      if (document.getElementsByClassName("like").length != 0) {
        $.ajax({
          url: "/weibo/blog/judgeBlogOfLike",
          type: "post",
          data: {
            id,
          },
          success: function (result) {
            let like = news[i].querySelector(".like");
            let icon = like.querySelector(".iconfont");
            let span = like.querySelector("span");
            if (result) {
              icon.innerHTML = "&#xe65f;";
              icon.style.color = "#feaf2f";
              span.style.color = "#feaf2f";
              like.f = 1;
            } else {
              like.f = 0;
            }
          },
          error: function () {},
        });
      }

      // 是否收藏
      if (document.getElementsByClassName("store").length != 0) {
        $.ajax({
          url: "/weibo/blog/judgeBlogOfConnection",
          type: "post",
          data: {
            id,
          },
          success: function (result) {
            if (result) {
              let store = news[i].querySelector(".store");
              let icon = store.querySelector(".iconfont");
              let span = store.querySelector("span");

              icon.innerHTML = "&#xe663";
              icon.style.color = "#feaf2f";
              span.style.color = "#feaf2f";
              store.f = 1;
            } else {
              store.f = 0;
            }
          },
        });
      }

      // 是否关注

      if (document.getElementsByClassName("top-attention-btn").length > 0) {
        let attention = news[i].querySelector(".top-attention-btn");

        $.ajax({
          url: `/weibo/user/judgeUserOfConnection`,
          type: "post",
          data: {
            id: uid,
          },
          success: function (result) {
            if (result) {
              attention.innerHTML = `
            <i class="iconfont">&#xe664;</i>已经关注
         `;
              attention.f = 1;
              // attention.setAttribute("disabled", true);
              attention.classList.add("already");
              // attention.style.pointEvents = "none";
            } else {
              attention.f = 0;
              attention.innerHTML = `
              <i class="iconfont">&#xe7df;</i>关注
           `;
              attention.classList.remove("already");
            }
          },
        });
      }
    }
  }
}

// 更多评论的弹窗
function more() {
  let moreReply = document.getElementsByClassName("more-reply");
  let moreMask = document.querySelector(".more-reply-mask");
  let thisitem1;
  if (moreReply.length > 0) {
    for (let i = 0; i < moreReply.length; i++) {
      moreReply[i].onclick = function () {
        thisitem1 = moreReply[i].parentNode.parentNode;

        let bid = moreReply[i].getAttribute("id");
        let index = moreReply[i].getAttribute("index");
        moreMask.style.display = "flex";
        document.body.style.overflow = "hidden";
        let contentComment = moreMask.querySelector(".content-comment");
        // 获取ajax请求,显示评论
        $.ajax({
          url: `/weibo/blog/getBlogComment?id=${bid}`,
          type: "get",
          success: function (result) {
            // 一级及二级评论的数据
            let item1 = result[index];
            let list = item1.list;
            contentComment.innerHTML = " ";
            contentComment.innerHTML =
              contentComment.innerHTML +
              `<div class="window-item1">
            <div class="item1-list">
          <a href="">
            <div class="item1-head">
              <img src="${item1.userAvatarUrl}" alt="" />
            </div>
          </a>
          <div class="item1-details">
            <a href="" class="details-name"><span>${item1.username}</span></a>
            <span>:</span>
            <span class="details-content">${item1.comment}</span>
            <div class="item1-bottom">
              <div class="bottom-time">${item1.publishTime}  ${item1.address}</div>
            </div>
          </div>
        </div>
        </div>`;
            for (let j = 0; j < list.length; j++) {
              if (list[j].likes == 0) {
                list[j].likes = "";
              }
              contentComment.innerHTML =
                contentComment.innerHTML +
                ` <div class="window-list2" cid=${list[j].id}  >
            <div class="window-list2-bar"></div>
            <div class="window-list2-details">
              <a href="" class="window-list2-name">
                <span>${list[j].username}</span>
                <span>:</span>
              </a>
              <span class="window-list2-content">${list[j].comment} </span>
            </div>
            <div class="window-list2-bottom">
              <div class="window-list2-time">${list[j].publishTime}${list[j].address}</div>
              <div class="window-list2-fn">
              <div class="window-list2-complain" otherId=${list[j].otherId}  onclick="removeSecondComment(this)">
              <i class="iconfont remove hidden">&#xe64c;</i>
              </div>
              
              <div class="window-list2-like" onclick="likesecWindow(this)" >
                <i class="iconfont">&#xe600;</i> <span>${list[j].likes}</span>
              </div>

            </div>
          </div>`;

              issecLike();
              judgecom();
            }
            issecLike();

            judgecom();
          },
          error: function (error) {
            console.log("失败");
          },
        });
      };
    }
  }

  // 取消弹窗
  let windowCancel = document.querySelector(".window-top-cancel");
  if (windowCancel) {
    windowCancel.onclick = function () {
      moreMask.style.display = "none";
      document.body.style.overflow = "inherit";
      // 重新渲染

      let bid = thisitem1.parentNode.parentNode.parentNode.getAttribute("bid");
      let comment = thisitem1.parentNode;
      $.ajax({
        url: `/weibo/blog/getBlogComment?id=${bid}`,
        type: "get",
        success: function (result) {
          comment.innerHTML = "";

          for (let i = 0; i < result.length; i++) {
            if (result[i].likes == 0) {
              result[i].likes = "";
            }
            comment.innerHTML =
              comment.innerHTML +
              ` <div class="item1" cid="${result[i].id}">
              <div class="comment-list">
                <a href="">
                 <div class="comment-head">
                    <img
                     
                      src="${result[i].userAvatarUrl}"
                      alt=""
                     />
                  </div>
                </a>
                <div class="comment-details">
                  <a href="" class="comment-name"> <span>${setText(
                    result[i].username
                  )}</span> </a>:
                  <span class="c-content">${setText(result[i].comment)}</span>
                <div class="comment-bottom">
                   <div class="c-time">${result[i].publishTime}   ${setText(
                result[i].address
              )}</div>
                   <div class="comment-fn">
                      <div class="c-complain" otherId=${
                        result[i].otherId
                      } cid="${
                result[i].id
              }" onclick="removeFirstComment(this)">
                      <i class="iconfont remove hidden">&#xe64c;</i>
                     
                      </div>
                      <div class="reply" cid=${result[i].id} logid=${
                result[i].uid
              }>
                        <i class="iconfont">&#xe695;</i>
                      </div>
                      <div class="c-like" onclick="likeComment(this)"  cid=${
                        result[i].id
                      }>
                        <i class="iconfont">&#xe600;</i><span>${
                          result[i].likes
                        }</span>
                      </div>
                    </div> 
                  </div>
                </div>
              </div>
           `;
          }
          let item1 = comment.getElementsByClassName("item1");
          for (let i = 0; i < result.length; i++) {
            // 二级评论的数据（数组）

            let list = result[i].list;

            if (result[i].likes == 0) {
              result[i].likes = " ";
            }

            if (list.length > 0) {
              for (let j = 0; j < 1; j++) {
                if (list[j].likes == 0) {
                  list[j].likes = "";
                }
                item1[i].innerHTML =
                  item1[i].innerHTML +
                  `<div class="list2" cid=${list[j].id}>
            <div class="list2-bar"></div>
            <div class="list2-details">
              <a href="" class="list2-name"><span>${setText(
                list[j].username
              )}:</span></a>
              <span class="list2-content">${setText(list[j].comment)}</span>
            </div>
            <div class="list2-bottom">
              <div class="list2-time">${list[j].publishTime}  ${
                    list[j].address
                  }</div>
                <div class="list2-fn">
                <div class="list2-complain" otherId=${
                  list[j].otherId
                } onclick="removeSecondComment(this)">
                <i class="iconfont remove hidden" >&#xe64c;</i>
                </div>
                
                <div class="list2-like" onclick="likeComment(this)">
                  <i class="iconfont">&#xe600;</i> <span>${list[j].likes}</span>
                </div>
              </div>
      </div>
            </div>
          </div>`;
              }

              // 下面循环结尾多一个</div>是对item1进行结尾
              if (list.length > 1) {
                item1[i].innerHTML =
                  item1[i].innerHTML +
                  `<div class="list2-more">
            <div class="list2-bar"></div>
                 <a href="javascript:;" class="more-reply" id=${bid} index=${i}>共${list.length}条回复</a>
                 <i class="iconfont bottom">&#xe62e;</i>
               </div>
             </div>`;
              } else {
                comment.innerHTML = comment.innerHTML + `</div>`;
              }
            }
            more();
            replyWindow();
            commentfn();
            judgecom(comment);
            judgeSecCom(comment);
            islike(comment);
            issecLike();
          }
        },
        error: function () {
          console.log("失败");
        },
      });
    };
  }
}

// 搜索功能
// 使用防抖
topinput.addEventListener("input", debounce(searchfn, 300));
function searchfn() {
  let topValue = topinput.value;
  let topinputText = JSON.stringify(topinput.value);

  $.ajax({
    url: `/weibo/blog/searchBlog?condition=${topValue}`,
    type: "get",
    success: function (result) {
      let aboutBlog = document.querySelector(".aboutBlog");
      let aboutUser = document.querySelector(".aboutUser");
      let searchHot = document.querySelector(".search-hot");
      let searchUser = document.querySelector(".search-user");
      aboutUser.innerHTML = `${topinputText}相关用户`;
      aboutBlog.innerHTML = `${topinputText}相关微博`;
      searchHot.innerHTML = "";
      searchUser.innerHTML = "";
      // 热搜和用户数据的数组
      let hotlistArr = result[0];
      let userlistArr = result[1];

      // 搜索的博文数据
      if (hotlistArr.length >= 3) {
        for (let i = 0; i < 3; i++) {
          if (!hotlistArr[i]) {
            continue;
          }
          searchHot.innerHTML += `
              <div>
              <a href="/weibo/blog/skipToBlog?label=${hotlistArr[i]}">
              <p class="blog-details"><i class="iconfont">&#xe65a;</i>${hotlistArr[i]}</p>
              </a>
             </div>`;
        }
      } else if (hotlistArr.length > 0) {
        for (let i = 0; i < hotlistArr.length; i++) {
          if (!hotlistArr[i]) {
            continue;
          }
          searchHot.innerHTML += `
              <div>
              <a href="/weibo/blog/skipToBlog?label=${hotlistArr[i]}">
              <span class="blog-details"><i class="iconfont">&#xe65a;</i> <span>${hotlistArr[i]}</span></span>
              </a>
             </div>`;
        }
      }
      // 搜索的用户数据
      if (userlistArr.length >= 3) {
        for (let i = 0; i < 3; i++) {
          if (!userlistArr[i].label) {
            userlistArr[i].label = "未知";
          }
          searchUser.innerHTML += `
              <div class="user-details"><a href="/weibo/user/toOnesInfo?id=${
                userlistArr[i].id
              }"><div class="userhead"><img src="${
            userlistArr[i].avatarUrl
          }" alt=""></div>
              <div class="user-message"><p class="message-name">${setText(
                userlistArr[i].username
              )}</p><p class="message-label">${setText(
            userlistArr[i].label
          )}</p></div></a>
            </div>
              `;
        }
      } else if (userlistArr.length > 0) {
        for (let i = 0; i < hotlistArr.length; i++) {
          if (!userlistArr[i].label) {
            userlistArr[i].label = "未知";
          }
          searchUser.innerHTML += `
              <div class="user-details"><a href="/weibo/user/toOnesInfo?id=${
                userlistArr[i].id
              }"><div class="userhead"><img src="${
            userlistArr[i].avatarUrl
          }" alt=""></div>
              <div class="user-message"><p class="message-name">${setText(
                userlistArr[i].username
              )}</p><p class="message-label">${setText(
            userlistArr[i].label
          )}</p></div></a>
            </div>`;
        }
      }
      // else {
      //   searchUser.innerHTML += ` <div class="user-details">暂无数据<div></div>
      // </div>`;
      // }
    },
    error: function (result) {
      console.log("搜索失败");
      console.log(result);
    },
  });
}

// 获取热搜数据
function gethot() {
  $.ajax({
    url: "/weibo/blog/getHotSearchBlog",
    type: "get",
    success: function (result) {
      let hot = document.querySelector(".allHotList");
      hot.innerHTML = "";
      for (let i = 0; i < 10; i++) {
        hot.innerHTML =
          hot.innerHTML +
          ` <div class="hot-list">
        <span class="rank${i + 1}">${
            i + 1
          }</span><a href="/weibo/blog/skipToBlog?label=${result[i]}">${
            result[i]
          }</a>
        </div>`;
      }
      hot.innerHTML += `<a href="/weibo/blog/getHotBlog" class="all-hot"><div>查看完整榜单</div></a>`;
    },
    error: function (result) {
      console.log(result);
    },
  });
}
// 刷新热搜数据
let refreshBtn = document.querySelector(".refresh");
refreshBtn.onclick = function () {
  gethot();
};
gethot();

// 发布评论
// 获取评论的内容为每个评论绑定事件
// 监听
// 要求自己的评论在最上边
function commentfn() {
  let commentText = document.getElementsByClassName("comment-text");
  let commentBtn = document.getElementsByClassName("comment-btn");
  let comment = document.getElementsByClassName("comment");
  if (commentText.length > 0) {
    for (let i = 0; i < commentText.length; i++) {
      commentText[i].addEventListener("input", function () {
        let commentContent = commentText[i].value;
        let bid = commentBtn[i].getAttribute("bid");

        commentBtn[i].onclick = function () {
          let commentContent = commentText[i].value;

          let user = getInfo();
          if (user.ban == 1) {
            showCustomAlert("您已被禁言，禁止评论！");
            return;
          }
          if (!setText(commentContent)) {
            return showCustomAlert("评论不能为空");
          }
          if (commentBtn[i].can == 1) {
            return showCustomAlert("您已发布过评论，请三分钟后再发布");
          } else {
            $.ajax({
              url: "/weibo/blog/publishFirstComment",
              type: "post",
              data: {
                id: bid,
                comment: commentContent,
              },
              success: function (result) {
                commentBtn[i].can = 1;

                $.ajax({
                  url: "/weibo/user/getLoginUserInfo",
                  type: "get",
                  data: {},
                  success: function (result) {
                    let name = result.username;
                    let avatarUrl = result.avatarUrl;
                    // 获取时间
                    let time = new Date();
                    // 进行渲染
                    comment[i].innerHTML =
                      ` <div class="item1" >
     <div class="comment-list">
       <a href="">
         <div class="comment-head">
           <img
             src="${avatarUrl}"
             th:src="@{/static/img/banner.jpg}"
             alt=""
           />
         </div>
       </a>
       <div class="comment-details">
         <a href="" class="comment-name"> <span >${name}</span> </a>:
         <span class="c-content" >${commentContent
           .replace(/</g, "&lt;")
           .replace(/>/g, "&gt;")}</span>
         <div class="comment-bottom">
           <div class="c-time">${formaData(time)}</div>
           <div class="comment-fn">
           <div class="c-complain" otherId=${
             user.id
           } onclick="removeFirstComment(this)">
           <i class="iconfont remove hidden">&#xe64c;</i>
          
           </div>
             <div class="reply">
               <i class="iconfont">&#xe695;</i>
             </div>
    
             <div class="c-like">
               <i class="iconfont">&#xe600;</i>
             </div>
           </div>
         </div>
       </div>
     </div>
    </div>` + comment[i].innerHTML;
                    showCustomAlert("评论成功", true);
                    commentText[i].value = "";
                    let commentBox=document.getElementsByClassName("assess")[i];
                    let commentNum=commentBox.querySelector("span").innerHTML;
                    console.log(Number(commentNum))
                    if(Number(likeText)==NaN){
                      commentNum=null;
                      commentNum=Number(commentNum)
                      commentNum++
                    }else{
                      commentNum=parseInt(commentNum)
                      commentNum++
                    }

                    commentlimit();
                    replyWindow();
                    judgecom(comment[i]);
                  },
                  error: function () {},
                });

                setTimeout(function () {
                  commentBtn[i].can = 0;
                }, 180000);
              },
              error: function (result) {
                console.log("评论失败");
              },
            });
          }
        };
      });
    }
  }
}

commentfn();

// 封装时间函数
let time = new Date();
// 定义格式化封装函数
function formaData(timer) {
  const year = timer.getFullYear();
  const month = timer.getMonth() + 1; // 由于月份从0开始，因此需加1
  const day = timer.getDate();
  const hour = timer.getHours();
  const minute = timer.getMinutes();
  const second = timer.getSeconds();
  return `${pad(year, 4)}-${pad(month)}-${pad(day)}  ${pad(hour)}:${pad(
    minute
  )}:${pad(second)}`;
}
// 定义具体处理标准
// timeEl 传递过来具体的数值：年月日时分秒
// total 字符串总长度 默认值为2
// str 补充元素 默认值为"0"
// padstart 字符串补全函数
function pad(timeEl, total = 2, str = "0") {
  return timeEl.toString().padStart(total, str);
}

YesOrNo();

// function GetRequest() {
//   var url = location.search; //获取url中"?"符后的字串
//   if (url.indexOf("?") != -1) {
//     //判断是否有参数
//     var str = url.substr(1);
//     //从第一个字符开始 因为第0个是?号 获取所有除问号的所有符串
//     var strs = str.split("=");
//     //用等号进行分隔
//     //（因为知道只有一个参数 所以直接用等号进分隔
//     //如果有多个参数 要用&号分隔 再用等号进行分隔）
//     return decodeURI(strs[1]);
//     //直接弹出第一个参数 （如果有多个参数 还要进行循环的）
//   }
// }

// 获取网址？后的参数(需要回显到input框)
function getUrlParam(index) {
  var urlinfo = window.location.href;
  //获取url
  var urlName = "";
  if (index === 1) {
    urlName = urlinfo.split("?")[1].split("=")[1].split("&")[0];
  }
  //拆分url得到”=”后面的参数
  return decodeURI(urlName);
}

// 防抖(用于搜索框)
function debounce(func, delay) {
  var timer = null;
  return function () {
    var that = this;
    var args = arguments;
    clearTimeout(timer);
    timer = setTimeout(function () {
      func.call(that, args);
    }, delay);
  };
}

// 判断用户个人页是否关注
let perAttention = document.querySelector(".per-attention-btn");

if (document.querySelector(".per-attention-btn")) {
  let perAttention = document.querySelector(".per-attention-btn");
  let uid = document.querySelector(".userInfo").getAttribute("uid");
  console.log(uid);
  $.ajax({
    url: `/weibo/user/judgeUserOfConnection`,
    type: "post",
    data: {
      id: uid,
    },
    success: function (result) {
      console.log(result);
      if (result) {
        perAttention.innerHTML = `
      <i class="iconfont">&#xe664;</i>已经关注
   `;
        perAttention.f = 1;
        perAttention.classList.add("already");
      } else {
        perAttention.f = 0;
        perAttention.innerHTML = `
        <i class="iconfont">&#xe7df;</i>关注
     `;
        perAttention.classList.remove("already");
      }
    },
  });

  perAttention.onclick = function () {
    if (perAttention.f == 0) {
      $.ajax({
        url: "/weibo/user/concernOtherUser",
        type: "post",
        data: {
          id: uid,
        },
        success: function (result) {
          perAttention.innerHTML = `<i class="iconfont">&#xe664;</i>已经关注`;
          perAttention.f = 1;
          perAttention.classList.add("already");
        },
        error: function () {},
      });
    } else {
      $.ajax({
        url: `/weibo/user/notConcernOtherUser`,
        type: "post",
        data: {
          id: uid,
        },
        success: function (result) {
          customConfirm("确定取消关注该用户？", function (result) {
            if (result) {
              perAttention.innerHTML = `<i class="iconfont">&#xe7df;</i>关注`;
              perAttention.classList.remove("already");
              perAttention.f = 0;
              YesOrNo();
            }
          });
        },
      });
    }
  };

  $.ajax({
    url: "/weibo/user/judgeUserOfConneciton",
    type: "post",
    data: {
      id: uid,
    },
    success: function (result) {
      if (result) {
        perAttention.innerHTML = `<i class="iconfont">&#xe664;</i>已经关注`;
        perAttention.f = 1;
        perAttention.classList.add("already");
      } else {
        perAttention.f = 0;
      }
    },
  });
}

// 尝试封装是否关注和点击关注函数
function judgeAndAtt(btn, uid) {
  btn.f = 0;
  btn.onclick = function () {
    if (perAttention.f == 0) {
      $.ajax({
        url: "/weibo/user/concernOtherUser",
        type: "post",
        data: {
          id: uid,
        },
        success: function (result) {
          btn.innerHTML = `<i class="iconfont">&#xe664;</i>已经关注`;
          btn.f = 1;
          btn.classList.add("already");
        },
        error: function () {},
      });
    } else {
      $.ajax({
        url: `/weibo/user/notConcernOtherUser`,
        type: "post",
        data: {
          id: uid,
        },
        success: function (result) {
          customConfirm("确定取消关注该用户？", function (result) {
            if (result) {
              btn.innerHTML = `<i class="iconfont">&#xe7df;</i>关注`;
              btn.classList.remove("already");
              btn.f = 0;
            }
          });
        },
      });
    }
  };

  $.ajax({
    url: "/weibo/user/judgeUserOfConneciton",
    type: "post",
    data: {
      id: uid,
    },
    success: function (result) {
      if (result) {
        btn.innerHTML = `<i class="iconfont">&#xe664;</i>已经关注`;
        btn.f = 1;
        btn.classList.add("already");
      } else {
        btn.f = 0;
      }
    },
  });
}

// 判断是否为空
// function isemp() {
//   let news = document.getElementsByClassName("news");
//   let idnews = document.querySelector("#news");
//   let users = document.getElementsByClassName("users");
//   let none = document.querySelector(".none");
//   if (news.length == 0 users.length == 0) {
//     idnews.innerHTML += `<div class="news empty">暂无数据</div>`;
//     none.classList.add("hidden");
//   }
// }
// isemp();

// 预览图片
function showModel(img) {
  let model = document.getElementById("model");
  let modelImg = document.getElementById("model-img");
  model.style.display = "flex";
  modelImg.src = img.src;
  document.body.style.overflow = "hidden";
}
function hideModel() {
  let model = document.getElementById("model");
  model.style.display = "none";
  document.body.style.overflow = "";
}
// 判断登录用户id和博文id 如果相同
// 如果相同，显示删除(b包括二级评论)

function judgecom(comment) {
  if (comment) {
    let item1 = comment.getElementsByClassName("item1");
    for (let i = 0; i < item1.length; i++) {
      let otherid = item1[i]
        .querySelector(".c-complain")
        .getAttribute("otherId");
      let list2 = item1[i].getElementsByClassName("list2");
      let remove = item1[i].querySelector(".remove");

      if (otherid == user.id) {
        remove.classList.remove("hidden");
      }
    }
  }

  let windowList2 = document.getElementsByClassName("window-list2");

  if (windowList2.length > 0) {
    for (let k = 0; k < windowList2.length; k++) {
      let otherid = windowList2[k]
        .querySelector(".window-list2-complain")
        .getAttribute("otherid");
      let remove = windowList2[k].querySelector(".remove");
      if (otherid == user.id) {
        remove.classList.remove("hidden");
      }
    }
  }
}

// 举报还是投诉
function reportfn(btn) {
  let rmDetails = btn.nextElementSibling;
  rmDetails.classList.toggle("hidden");
  let otherid = btn.getAttribute("otherid");
  let bid = btn.getAttribute("bid");
  let tipoffLi = rmDetails.querySelector(".tip-off-li");
  let removeLi = rmDetails.querySelector(".remove-li");
  if (otherid == user.id) {
    tipoffLi.classList.add("hidden");
  } else {
    removeLi.classList.add("hidden");
  }
  let all = document.querySelector("body");
  all.onclick = function (e) {
    if (!rmDetails.contains(e.target) && !btn.contains(e.target)) {
      rmDetails.classList.add("hidden");
    }
  };
}
// 删除文章
function removeBlog(btn) {
  // 利用jq可以删除该按钮的指定祖先节点
  customConfirm("确定删除该文章吗？(一经删除不可恢复)", function (result) {
    if (result) {
      let id = btn.getAttribute("bid");
      $.ajax({
        url: `${baseurl}/deleteTheBlog`,
        type: "post",
        data: {
          id,
        },
        success: function (result) {
          $(btn).parents(".news").remove();
          showCustomAlert("删除成功", true);
        },
      });
    }
  });
}
// 投诉文章
function tipOffFn(btn) {
  let bid = btn.getAttribute("bid");
  let submitBtn = document.querySelector(".btn-sure");
  let toMask = document.querySelector(".tip-off");
  toMask.classList.remove("hidden");
  let radios = document.querySelectorAll('input[name="radioName"]');
  let close = toMask.querySelector(".close");
  document.body.overflow = "hidden";
  close.onclick = function () {
    toMask.classList.add("hidden");
    document.body.style.overflow = "";
  };

  let otherReason = document.querySelector(".other-reason");
  let radio8 = document.getElementById("radio8");
  // 监听单选框
  for (let i = 0; i < radios.length; i++) {
    radios[i].addEventListener("change", function () {
      if (radio8.checked) {
        otherReason.classList.remove("hidden");
      } else {
        otherReason.classList.add("hidden");
      }
    });
  }

  submitBtn.onclick = function () {
    let msg;
    let other = document.querySelector(".other-ta").value;
    if ($('input:radio[name="radioName"]:checked').next().text() == "其他") {
      if (other) {
        msg = other;
      } else {
        return showCustomAlert("请说明举报理由");
      }
    } else {
      msg = $('input:radio[name="radioName"]:checked').next().text();
    }
    $.ajax({
      url: `${baseurl}/reportBlog`,
      type: "post",
      data: {
        bid,
        msg,
      },
      success: function () {
        toMask.classList.add("hidden");
        document.body.style.overflow = "";
        showCustomAlert("感谢您的举报,请等待审核", true);
      },
    });
  };
}

// 判断是否点赞一级评论
function islike(comment) {
  let like = comment.getElementsByClassName("c-like");

  if (like.length !== 0) {
    for (let i = 0; i < like.length; i++) {
      let cid = $(like[i]).parents(".item1").attr("cid");
      $.ajax({
        url: `${baseurl}/judgeCommentOfLike`,
        type: "post",
        data: {
          id: cid,
        },
        success: function (result) {
          if (result) {
            let icon = like[i].querySelector(".iconfont");
            let span = like[i].querySelector("span");
            icon.innerHTML = "&#xe65f;";
            like[i].classList.add("al-like");
          } else {
          }
        },
      });
    }
  }
}

function setText(val) {
  let msg = val.replace(/</g, "&lt;").replace(/>/g, "&gt;"); //执行替换成空字符
  msg = msg.replace(/\s/g, ""); //去掉所有的空格（中文空格、英文空格都会被替换）
  //去掉所有的换行符
  return msg; //获文本文字内容的前100个字符
}

function removeFirstComment(btn) {
  let cid = btn.getAttribute("cid");
  customConfirm("确定删除该评论吗", function (result) {
    if (result) {
      $.ajax({
        url: `${baseurl}/deleteComment`,
        type: "post",
        data: {
          id: cid,
        },
        success: function () {
          let item1 = $(btn).parents(".item1");
          item1.remove();
        },
      });
    }
  });
}
// 点赞评论或取消
function likeComment(btn) {
  let cid = btn.getAttribute("cid");

  let icon = btn.querySelector(".iconfont");
  let span = btn.querySelector("span");
  let likeText;
  if (span) {
    likeText = 0 + span.innerHTML;
  }

  if (btn.classList.contains("al-like")) {
    // 如果点过赞，则取消
    $.ajax({
      url: `${baseurl}/notLikeComment`,
      type: "post",
      data: {
        id: cid,
      },
      success: function () {
        btn.classList.remove("al-like");
        icon.innerHTML = "&#xe62b;";
        if (span) {
          if (Number(likeText) > 1) {
            likeText = Number(likeText);
            likeText--;
          } else {
            likeText = parseInt(likeText);
            likeText = null;
          }
          span.innerHTML = likeText;
        }
      },
      error: function () {},
    });
  } else {
    //如果没点过赞，则加一
    $.ajax({
      url: `${baseurl}/likeComment`,
      type: "post",
      data: {
        id: cid,
      },
      success: function () {
        icon.innerHTML = "&#xe65f;";
        btn.classList.add("al-like");
        if (span) {
          if (Number(likeText) == NaN) {
            likeText = null;
            likeText = Number(likeText);
            likeText++;
          } else {
            likeText = parseInt(likeText);
            likeText++;
          }
          span.innerHTML = likeText;
        }
      },
    });
  }
}

// 判断是否点赞二级评论
function issecLike() {
  let secLike = document.getElementsByClassName("list2-like");
  let window = document.querySelector(".more-window");
  let windowLike = window.getElementsByClassName("window-list2-like");

  if (secLike.length !== 0) {
    for (let i = 0; i < secLike.length; i++) {
      let cid = $(secLike[i]).parents(".list2").attr("cid");
      $.ajax({
        url: `${baseurl}/judgeCommentOfLike`,
        type: "post",
        data: {
          id: cid,
        },
        success: function (result) {
          if (result) {
            let icon = secLike[i].querySelector(".iconfont");
            let span = secLike[i].querySelector("span");
            icon.innerHTML = "&#xe65f;";
            secLike[i].classList.add("al-like");
          } else {
          }
        },
      });
    }
  }
  if (windowLike.length !== 0) {
    for (let i = 0; i < windowLike.length; i++) {
      let cid = $(windowLike[i]).parents(".window-list2").attr("cid");
      $.ajax({
        url: `${baseurl}/judgeCommentOfLike`,
        type: "post",
        data: {
          id: cid,
        },
        success: function (result) {
          if (result) {
            let icon = windowLike[i].querySelector(".iconfont");
            let span = windowLike[i].querySelector("span");
            icon.innerHTML = "&#xe65f;";
            windowLike[i].classList.add("al-like");
          } else {
          }
        },
      });
    }
  }
}
// 点赞弹窗的二级
function likesecWindow(btn) {
  let windowList2 = $(btn).parents(".window-list2");
  let cid = windowList2.attr("cid");
  let icon = btn.querySelector(".iconfont");
  let span = btn.querySelector("span");
  let likeText = 0 + span.innerHTML;
  if (btn.classList.contains("al-like")) {
    // 如果点过赞，则取消
    $.ajax({
      url: `${baseurl}/notLikeComment`,
      type: "post",
      data: {
        id: cid,
      },
      success: function () {
        btn.classList.remove("al-like");
        icon.innerHTML = "&#xe62b;";

        if (Number(likeText) > 1) {
          likeText = Number(likeText);
          likeText--;
        } else {
          likeText = parseInt(likeText);
          likeText = null;
        }
        span.innerHTML = likeText;
      },
      error: function () {},
    });
  } else {
    //如果没点过赞，则加一
    $.ajax({
      url: `${baseurl}/likeComment`,
      type: "post",
      data: {
        id: cid,
      },
      success: function () {
        icon.innerHTML = "&#xe65f;";
        btn.classList.add("al-like");
        if (Number(likeText) == NaN) {
          likeText = null;
          likeText = Number(likeText);
          likeText++;
        } else {
          likeText = parseInt(likeText);
          likeText++;
        }
        span.innerHTML = likeText;
      },
    });
  }
}

// 判断二级评论是否可以删除
function judgeSecCom(comment) {
  let list2 = comment.getElementsByClassName("list2");

  if (list2.length > 0) {
    for (let j = 0; j < list2.length; j++) {
      let otherid = list2[j]
        .querySelector(".list2-complain")
        .getAttribute("otherid");
      let remove = list2[j].querySelector(".remove");
      if (otherid == user.id) {
        remove.classList.remove("hidden");
      }
    }
  }
}

// 删除二级
function removeSecondComment(btn) {
  let cid = btn.parentNode.parentNode.parentNode.getAttribute("cid");

  customConfirm("确定删除该评论吗", function (result) {
    if (result) {
      $.ajax({
        url: `${baseurl}/deleteComment`,
        type: "post",
        data: {
          id: cid,
        },
        success: function () {
          let windowList2 = btn.parentNode.parentNode.parentNode;
          windowList2.remove();
        },
      });
    }
  });
}

// 判断评论页面的点赞功能
function isCommentLike() {
  let likeComment = document.getElementsByClassName("likeComment");

  if (likeComment.length > 0) {
    for (let i = 0; i < likeComment.length; i++) {
      let cid = likeComment[i].getAttribute("cid");
      $.ajax({
        url: `${baseurl}/judgeCommentOfLike`,
        type: "post",
        data: {
          id: cid,
        },
        success: function (result) {
          if (result) {
            let icon = likeComment[i].querySelector(".iconfont");

            icon.innerHTML = "&#xe65f;";
            likeComment[i].classList.add("al-like");
          } else {
          }
        },
      });
    }
  }
}
isCommentLike();
let nighrcolor = "black";
let backColor = "#191919";
let orange = "#ff8200";
let gray = "#2c2c2c";
let iconcolor = "#d3d3d3";
let font = "#bfbfbf";
// 夜间模式
var n = localStorage.getItem("n") || 0;
let nightbtn = document.querySelector(".top-pattern-btn");
nightbtn.onclick = function () {
  let fn = document.querySelector("#fn");
  let iconfont = fn.getElementsByClassName("iconfont");
  let icon = nightbtn.querySelector(".iconfont");
  let logo = document.querySelector(".logo");
  let list = document.querySelector(".list");
  let top = document.querySelector(".top");
  let news = document.getElementsByClassName("news");
  let sign = document.querySelector(".sign");
  let hot = document.querySelector("#hot");
  let window = document.querySelector(".window");
  let moreWindow = document.querySelector(".more-window");
  let publishBlog = document.querySelector(".publishBlog");
  let focusList = document.querySelector(".focusList");
  let pswdChangeBox = document.querySelector(".pswdChangeBox");
  let userInfo = document.querySelector(".userInfo");
  let fansList = document.querySelector(".fansList");
  let users = document.getElementsByClassName("users");
  let CPM = document.querySelector(".CPM");
  let infoChangeBox = document.querySelector(".infoChangeBox");
  let searchList = document.querySelector(".search-list");
  if (!localStorage.getItem("n")) {
    localStorage.setItem("n", 0);
    nightbtn.classList.add("al-night");
  } else if (localStorage.getItem("n") == 1) {
    nightbtn.classList.remove("al-night");
  } else if (localStorage.getItem("n") == 0) {
    nightbtn.classList.add("al-night");
  }

  // 如果是夜间
  if (nightbtn.classList.contains("al-night")) {
    localStorage.n = 1;
    document.body.style.backgroundColor = "black";
    document.querySelector(".top").style.backgroundColor = "#191919";
    top.classList.add("nighttop");
    logo.querySelector("img").src = " /weibo/static/img/logo2.png";
    // 设置左边栏样式
    list.classList.add("nightlist");
    icon.innerHTML = "&#xe6c8;";
    // 设置中间部分样式
    if (news.length > 0) {
      for (let i = 0; i < news.length; i++) {
        news[i].classList.add("night");
      }
    }
    if (searchList) {
      searchList.classList.add("nightSearch");
    }
    if (users.length > 0) {
      for (let i = 0; i < users.length; i++) {
        users[i].classList.add("nightUser");
      }
    }
    if (pswdChangeBox) {
      pswdChangeBox.classList.add("nightpswd");
    }
    if (infoChangeBox) {
      infoChangeBox.classList.add("nightpswd");
    }
    if (CPM) {
      CPM.classList.add("night");
    }

    // 热搜样式
    hot.classList.add("nighthot");
    // 回复弹窗
    if (window) {
      window.classList.add("night");
    }
    if (moreWindow) {
      moreWindow.classList.add("night");
    }
    if (publishBlog) {
      publishBlog.classList.add("night");
    }
    if (focusList) {
      focusList.classList.add("nightFocus");
    }
    if (userInfo) {
      userInfo.classList.add("night");
    }
    if (fansList) {
      fansList.classList.add("nightFocus");
    }
  } else {
    localStorage.n = 0;
    document.body.style.backgroundColor = "";
    document.querySelector(".top").style.backgroundColor = "";
    // for (let i = 0; i < icon.length; i++) {
    //   iconfont[i].style.color = "";
    //   iconfont[i].onmousemove = function () {
    //     icon[i].style.backgroundColor = "";
    //   };
    //   iconfont[i].onmouseleave = function () {
    //     icon[i].style.backgroundColor = "";
    //   };
    // }
    top.classList.remove("nighttop");
    logo.querySelector("img").src = " /weibo/static/img/logo.png";
    // 设置左边栏样式
    list.classList.remove("nightlist");
    icon.innerHTML = "&#xe6d9;";
    if (CPM) {
      CPM.classList.remove("night");
    }
    if (searchList) {
      searchList.classList.remove("nightSearch");
    }
    // 设置中间部分样式
    if (news.length > 0) {
      for (let i = 0; i < news.length; i++) {
        news[i].classList.remove("night");
      }
    }
    if (infoChangeBox) {
      infoChangeBox.classList.remove("nightpswd");
    }
    if (users.length > 0) {
      for (let i = 0; i < users.length; i++) {
        users.classList.remove("nightUser");
      }
    }

    // 热搜样式
    hot.classList.remove("nighthot");
    // 回复弹窗
    if (pswdChangeBox) {
      pswdChangeBox.classList.remove("nightpswd");
    }
    if (window) {
      window.classList.remove("night");
    }
    if (moreWindow) {
      moreWindow.classList.remove("night");
    }
    if (publishBlog) {
      publishBlog.classList.remove("night");
    }
    if (focusList) {
      focusList.classList.remove("nightFocus");
    }
    if (userInfo) {
      userInfo.classList.remove("night");
    }
    if (fansList) {
      fansList.classList.remove("nightFocus");
    }
  }
};
// 模式转换
function switchoverfn() {
  let fn = document.querySelector("#fn");
  let iconfont = fn.getElementsByClassName("iconfont");
  let icon = nightbtn.querySelector(".iconfont");
  let logo = document.querySelector(".logo");
  let list = document.querySelector(".list");
  let top = document.querySelector(".top");
  let news = document.getElementsByClassName("news");
  let sign = document.querySelector(".sign");
  let hot = document.querySelector("#hot");
  let window = document.querySelector(".window");
  let moreWindow = document.querySelector(".more-window");
  let publishBlog = document.querySelector(".publishBlog");
  let focusList = document.querySelector(".focusList");
  let pswdChangeBox = document.querySelector(".pswdChangeBox");
  let userInfo = document.querySelector(".userInfo");
  let fansList = document.querySelector(".fansList");
  let users = document.getElementsByClassName("users");
  let CPM = document.querySelector(".CPM");
  let infoChangeBox = document.querySelector("infoChangeBox");
  let searchList = document.querySelector(".search-list");
  if (localStorage.getItem("n")) {
    if (localStorage.getItem("n") == 0) {
      localStorage.n = 0;
      document.body.style.backgroundColor = "";
      document.querySelector(".top").style.backgroundColor = "";

      logo.querySelector("img").src = " /weibo/static/img/logo.png";
      // 设置左边栏样式
      list.classList.remove("nightlist");
      top.classList.remove("nighttop");
      // 设置中间部分样式
      if (news.length > 0) {
        for (let i = 0; i < news.length; i++) {
          news[i].classList.remove("night");
        }
      }
      if (users.length > 0) {
        for (let i = 0; i < user.length; i++) {
          users[i].classList.remove("nightUser");
        }
      }
      if (searchList) {
        searchList.classList.remove("nightSearch");
      }

      // 热搜样式
      icon.innerHTML = "&#xe6d9;";
      hot.classList.remove("nighthot");
      if (pswdChangeBox) {
        pswdChangeBox.classList.remove("nightpswd");
      }
      if (CPM) {
        CPM.classList.remove("night");
      }
      if (infoChangeBox) {
        infoChangeBox.classList.remove("nightpswd");
      }
      // 回复弹窗
      if (window) {
        window.classList.remove("night");
      }
      if (moreWindow) {
        moreWindow.classList.remove("night");
      }
      if (publishBlog) {
        publishBlog.classList.remove("night");
      }

      if (focusList) {
        focusList.classList.remove("nightFocus");
      }
      if (userInfo) {
        userInfo.classList.remove("night");
      }
      if (fansList) {
        fansList.classList.remove("nightFocus");
      }
    } else if (localStorage.getItem("n") == 1) {
      localStorage.n = 1;
      document.body.style.backgroundColor = "black";
      document.querySelector(".top").style.backgroundColor = "#191919";

      top.classList.add("nighttop");
      logo.querySelector("img").src = " /weibo/static/img/logo2.png";
      // 设置左边栏样式
      list.classList.add("nightlist");
      icon.innerHTML = "&#xe6d9;";
      if (pswdChangeBox) {
        pswdChangeBox.classList.add("nightpswd");
      }
      if (searchList) {
        searchList.classList.add("nightSearch");
      }
      if (CPM) {
        CPM.classList.add("night");
      }

      // 设置中间部分样式
      if (news.length > 0) {
        for (let i = 0; i < news.length; i++) {
          news[i].classList.add("night");
        }
      }
      if (users.length > 0) {
        for (let i = 0; i < users.length; i++) {
          users[i].classList.add("nightUser");
        }
      }
      // 热搜样式
      hot.classList.add("nighthot");
      // 回复弹窗
      if (window) {
        window.classList.add("night");
      }
      if (moreWindow) {
        moreWindow.classList.add("night");
      }
      if (publishBlog) {
        publishBlog.classList.add("night");
      }
      if (focusList) {
        focusList.classList.add("nightFocus");
      }
      if (userInfo) {
        userInfo.classList.add("night");
      }
      if (fansList) {
        fansList.classList.add("nightFocus");
      }
    }
  }
}
switchoverfn();
let allType = document.querySelector(".all-type");

function getType() {
  allType.innerHTML = "";
  if (allType.classList.contains("hidden")) {
    allType.classList.remove("hidden");
    $.ajax({
      url: `${baseurl}/getAllType`,
      type: "get",
      success: function (result) {
        let types = result.data;
        for (let i = 5; i < types.length; i++) {
          let div = document.createElement("div");
          div.innerHTML = `${types[i].type}`;
          div.classList.add("type-item");
          allType.appendChild(div);
          div.setAttribute("data-id", `${types[i].id}`);
        }
      },
    });
  } else {
    allType.classList.add("hidden");
  }
}

//事件委托

// 渲染类型文章


let body=document.querySelector("#news")
// function getBlogByType (e) {
//     let conditon = e.target.innerHTML;
//     let typeId = e.target.dataset.id;
//     let signs = document.getElementsByClassName("sign-item");
// let type=e.target.innerHTML;
//     console.log(type)
//     if (
//       (e.target.classList.contains("type-item") ||
//         e.target.classList.contains("sign-item")) &&
//       e.target.innerHTML != "热门"
//     ) {
//       for (let i = 0; i < signs.length; i++) {
//         signs[i].className = "sign-item";
//       }
//       e.target.classList.add("color");
//       $.ajax({
//         url: `${baseurl}/getBlogByType`,
//         type: "get",
//         data: {
//           id: typeId,
//         },
//         success: function (rs) {
//           let allnews = document.querySelector("#news");
//           let result = rs.data;
//           console.log(result);
//           let alNews = document.querySelector(".al-news");
//           console.log("qingqiu");
//           alNews.innerHTML = "";
//           if(result.length==0){
//             alNews.innerHTML=`<div class="news empty">暂无数据</div>>`
//
//           }
//           for (let i = 0; i < result.length; i++) {
//             let data = result[i];
//             if (data.transmit == 0) {
//               data.transmit = "分享";
//             }
//             if (data.likes == 0) {
//               data.likes = "点赞";
//             }
//             if (data.comment == 0) {
//               data.comment = "评论";
//             }
//             alNews.innerHTML += `<div class="news add " uid="${result[i].uid}" bid="${result[i].id}">
//           <div class="news-top">
//             <a href="/weibo/user/toOnesInfo(id=${result[i].uid})" class="head-link">
//               <div class="head">
//                 <img
//                         src="${result[i].userAvatarUrl}"
//                         alt=""
//                 />
//               </div>
//             </a>
//             <div class="top-details">
//               <a href="" class="name">
//                 <p >${result[i].username}</p>
//               </a>
//               <p class="time">${result[i].time}</p>
//             </div>
//             <div class="top-attention">
//               <button class="top-attention-btn">
//                 <i class="iconfont">&#xe7df;</i>关注
//               </button>
//             </div>
//             <div class="report-remove " >
//               <div class="rm-icon" bid="${result[i].id}" otherid="${result[i].uid}" onclick="reportfn(this)"><i class="iconfont">&#xe62e;</i></div>
//               <ul class="rm-detials hidden">
//                 <li class="tip-off-li" bid="${result[i].id}">投诉</li>
//                 <li class="remove-li" bid="${result[i].id}">删除</li>
//               </ul>
//             </div>
//           </div>
//           <div class="news-container">
//             <div  class="container">
//               <span class="container-text" >${result[i].text}</span>
//
//               <span class="collapse">收起</span>
//             </div>
//
//             <div class="news-content">
//             </div>
//           </div>
//           <!-- 底部博文功能 -->
//           <div class="foot">
//             <div class="share">
//               <i class="iconfont">&#xe62f;</i>
//               <span
//
//               >${result[i].transmit}</span
//               >
//             </div>
//             <div class="assess" bid="${result[i].id}">
//               <i class="iconfont">&#xe695;</i>
//               <span
//               >${result[i].comment}</span
//               >
//             </div>
//             <div class="store">
//             <i class="iconfont">&#xe647;</i>
//             <span>收藏</span>
//           </div>
//             <div class="like">
//               <i class="iconfont">&#xe62b;</i>
//               <span
//               >${result[i].likes}</span
//               >
//             </div>
//           </div>
//           <div class="spread">
//             <textarea
//                     placeholder="请发布你的评论"
//                     class="comment-text"
//             ></textarea>
//             <span class="comment-ddl">还可输入140字</span>
//             <button class="comment-btn disable">评论</button>
//             <!-- 评论 -->
//             <div class="comment">
//               <!-- 一级评论 -->
//               <div class="item1">
//                 <div class="comment-list">
//                   <a href="">
//                     <div class="comment-head">
//                       <img
//                               src="../img/banner.jpg"
//                               th:src="@{/static/img/banner.jpg}"
//                               alt=""
//                       />
//                     </div>
//                   </a>
//                   <div class="comment-details">
//                     <a href="" class="comment-name"> <span>XXX</span> </a>:
//                     <span class="c-content">今天天气真好1</span>
//                     <div class="comment-bottom">
//                       <div class="c-time">3-18</div>
//                       <div class="comment-fn">
//                         <div class="c-complain">
//                           <i class="iconfont">&#xe6a9;</i>
//                         </div>
//                         <div class="reply">
//                           <i class="iconfont">&#xe695;</i>
//                         </div>
//                         <div class="c-like">
//                           <i class="iconfont">&#xe600;</i>
//                           12
//                         </div>
//                       </div>
//                     </div>
//                   </div>
//                 </div>
//                 <!-- 二级评论 -->
//                 <div class="list2">
//                   <div class="list2-bar"></div>
//                   <div class="list2-details">
//                     <a href="" class="list2-name"><span>XXX:</span></a>
//                     <span class="list2-content">1111111111</span>
//                   </div>
//                   <div class="list2-bottom">
//                     <div class="list2-time">3-18</div>
//                   </div>
//                 </div>
//
//                 <div class="list2">
//                   <a class="more-reply"
//                   >共2条回复
//                     <i class="iconfont">&#xe62e;</i>
//                   </a>
//                 </div>
//               </div>
//               <!-- 二级评论 -->
//             </div>
//             <div class="blog-skip hidden">
//       <a href="/weibo/blog/skipInEnvelope?id=${result[i].id}">查看全部评论 ></a>
//     </div>
//           </div>
//         </div>`;
//             let add = document.getElementsByClassName("add")[i];
//             let content = add.querySelector(".news-content");
//             let picture = result[i].pictureUrl;
//             if (picture.length > 0) {
//               for (let j = 0; j < picture.length; j++) {
//                 content.innerHTML += `<div class="news-content-img"  >
//           <img src="${picture[j]}"alt="" onclick="showModel(this)">
//         </div>`;
//               }
//             }
//             more();
//             assessBtn();
//             commentfn();
//             YesOrNo();
//             func();
//             replyWindow();
//             collapsefn();
//           }
//          allnews.innerHTML += `<p class="none">暂时没有其他内容了</p>`;
//         },
//       });
//     }
//   };


  body.addEventListener("click", function (e) {

    if (
      (e.target.classList.contains("type-item") ||
        e.target.classList.contains("sign-item")) &&
      e.target.innerHTML != "热门"
    ) {
      let conditon = e.target.innerHTML;
      let typeId = e.target.dataset.id;
      let signs = document.getElementsByClassName("sign-item");
      let type=e.target.innerHTML;
      for (let i = 0; i < signs.length; i++) {
        signs[i].className = "sign-item";
      }
      e.target.classList.add("color");
      $.ajax({
        url: `${baseurl}/getBlogByType`,
        type: "get",
        data: {
          id: typeId,
        },
        success: function (rs) {
          let allnews = document.querySelector("#news");
          let result = rs.data;
          console.log(result);
          let alNews = document.querySelector(".al-news");
          console.log("qingqiu");
          alNews.innerHTML = "";
          if(result.length==0){
            alNews.innerHTML=`<div class="news empty">暂无数据</div>>`

          }
          for (let i = 0; i < result.length; i++) {
            let data = result[i];
            if (data.transmit == 0) {
              data.transmit = "分享";
            }
            if (data.likes == 0) {
              data.likes = "点赞";
            }
            if (data.comment == 0) {
              data.comment = "评论";
            }
            alNews.innerHTML += `<div class="news add " uid="${result[i].uid}" bid="${result[i].id}">
          <div class="news-top">
            <a href="/weibo/user/toOnesInfo(id=${result[i].uid})" class="head-link">
              <div class="head">
                <img
                        src="${result[i].userAvatarUrl}"
                        alt=""
                />
              </div>
            </a>
            <div class="top-details">
              <a href="" class="name">
                <p >${result[i].username}</p>
              </a>
              <p class="time">${result[i].time}</p>
            </div>
            <div class="top-attention">
              <button class="top-attention-btn">
                <i class="iconfont">&#xe7df;</i>关注
              </button>
            </div>
            <div class="report-remove " >
              <div class="rm-icon" bid="${result[i].id}" otherid="${result[i].uid}" onclick="reportfn(this)"><i class="iconfont">&#xe62e;</i></div>
              <ul class="rm-detials hidden">
                <li class="tip-off-li" bid="${result[i].id}">投诉</li>
                <li class="remove-li" bid="${result[i].id}">删除</li>
              </ul>
            </div>
          </div>
          <div class="news-container">
            <div  class="container">
              <span class="container-text" >${result[i].text}</span>

              <span class="collapse">收起</span>
            </div>

            <div class="news-content">
            </div>
          </div>
          <!-- 底部博文功能 -->
          <div class="foot">
            <div class="share">
              <i class="iconfont">&#xe62f;</i>
              <span

              >${result[i].transmit}</span
              >
            </div>
            <div class="assess" bid="${result[i].id}">
              <i class="iconfont">&#xe695;</i>
              <span
              >${result[i].comment}</span
              >
            </div>
            <div class="store">
            <i class="iconfont">&#xe647;</i>
            <span>收藏</span>
          </div>
            <div class="like">
              <i class="iconfont">&#xe62b;</i>
              <span
              >${result[i].likes}</span
              >
            </div>
          </div>
          <div class="spread">
            <textarea
                    placeholder="请发布你的评论"
                    class="comment-text"
            ></textarea>
            <span class="comment-ddl">还可输入140字</span>
            <button class="comment-btn disable">评论</button>
            <!-- 评论 -->
            <div class="comment">
              <!-- 一级评论 -->
              <div class="item1">
                <div class="comment-list">
                  <a href="">
                    <div class="comment-head">
                      <img
                              src="../img/banner.jpg"
                              th:src="@{/static/img/banner.jpg}"
                              alt=""
                      />
                    </div>
                  </a>
                  <div class="comment-details">
                    <a href="" class="comment-name"> <span>XXX</span> </a>:
                    <span class="c-content">今天天气真好1</span>
                    <div class="comment-bottom">
                      <div class="c-time">3-18</div>
                      <div class="comment-fn">
                        <div class="c-complain">
                          <i class="iconfont">&#xe6a9;</i>
                        </div>
                        <div class="reply">
                          <i class="iconfont">&#xe695;</i>
                        </div>
                        <div class="c-like">
                          <i class="iconfont">&#xe600;</i>
                          12
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <!-- 二级评论 -->
                <div class="list2">
                  <div class="list2-bar"></div>
                  <div class="list2-details">
                    <a href="" class="list2-name"><span>XXX:</span></a>
                    <span class="list2-content">1111111111</span>
                  </div>
                  <div class="list2-bottom">
                    <div class="list2-time">3-18</div>
                  </div>
                </div>

                <div class="list2">
                  <a class="more-reply"
                  >共2条回复
                    <i class="iconfont">&#xe62e;</i>
                  </a>
                </div>
              </div>
              <!-- 二级评论 -->
            </div>
            <div class="blog-skip hidden">
      <a href="/weibo/blog/skipInEnvelope?id=${result[i].id}">查看全部评论 ></a>
    </div>
          </div>
        </div>`;
            let add = document.getElementsByClassName("add")[i];
            let content = add.querySelector(".news-content");
            let picture = result[i].pictureUrl;
            if (picture.length > 0) {
              for (let j = 0; j < picture.length; j++) {
                content.innerHTML += `<div class="news-content-img"  >
          <img src="${picture[j]}"alt="" onclick="showModel(this)">
        </div>`;
              }
            }
            more();
            assessBtn();
            commentfn();
            YesOrNo();
            func();
            replyWindow();
            collapsefn();
          }
          allnews.innerHTML += `<p class="none">暂时没有其他内容了</p>`;
        },
      });
    }
  });


// 渲染
function hotType() {
  let items = document.getElementsByClassName("sign-item");
  $.ajax({
    url: `${baseurl}/getAllType`,
    type: "get",
    success: function (result) {
      let types = result.data;
      for (let i = 1; i < items.length; i++) {
        console.log(items[i]);
        items[i].innerHTML = `${types[i - 1].type}`;
        items[i].setAttribute("data-id", `${types[i - 1].id}`);
      }
    },
  });
}

hotType();
